<template>
  <div class="app-container">
    <!-- 输入表单 -->
    <el-form label-width="120px">
      <el-form-item label="借款额度">
        <el-input-number v-model="integralGrade.borrowAmount" :min="0" />
      </el-form-item>
      <el-form-item label="积分区间开始">
        <el-input-number v-model="integralGrade.integralStart" :min="0" />
      </el-form-item>
      <el-form-item label="积分区间结束">
        <el-input-number v-model="integralGrade.integralEnd" :min="0" />
      </el-form-item>
      <el-form-item>
        <el-button
          :disabled="saveBtnDisabled"
          type="primary"
          @click="saveOrUpdate()"
        >
          保存
        </el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import integraGradeApi from '@/api/core/integral-grade'
export default {
  data() {
    return {
      //积分等级对象
      integralGrade: {},
      saveBtnDisabled: false,
    }
  },
  methods: {
    saveOrUpdate() {
      //新增方法
      this.saveBtnDisabled = true
      if (!this.integralGrade.id) {
        this.saveData()
      } else {
        //更新方法
        this.updataData()
      }
    },
    saveData() {
      integraGradeApi.save(this.integralGrade).then((res) => {
        this.$message.success(res.message)
        this.$router.push('/core/integral-grade/list')
      })
    },
    updataData() {
      integraGradeApi.updateById(this.integralGrade).then((res) => {
        this.$message.success(res.message)
        this.$router.push('/core/integral-grade/list')
      })
    },
    flahById(id) {
      integraGradeApi.getById(id).then((res) => {
        this.integralGrade = res.data.record
      })
    },
  },
  created() {
    if (this.$route.params.id) {
      this.flahById(this.$route.params.id)
    }
  },
}
</script>
<style scoped>
</style>